import BaseApi from "@/api/BaseApi";

export default class XRouter {

    public static goTo(url: string, complete?: any) {
        url = this.hoke(url);
        uni.navigateTo({
            url: url,
            complete: (com) => {
                console.log(com);
                if (complete!= null) {
                    complete();
                }
            }
        });
    }

    //判断是否那些需要特殊登录拦截
    public static hoke(url: string): string {
        if (BaseApi.instance().isLogin) {
            return url;
        }
        const arHit: string[] = [];
        let xurl = url;
        for (var i = 0; i < arHit.length; i++) {
            if (url.indexOf(arHit[i]) > -1) {
                BaseApi.instance().setNexComponentParam({"returnPage": url});
                xurl = "/pages/common/bind_phone_view";
                break;
            }
        }
        return xurl;
    }


    public static redirect(url: string) {
        uni.redirectTo({
            url: url
        });
    }

    public static back(num: any) {
        var x: any = {delta: num};
        uni.navigateBack(x);
    }
}